<%@page import="java.sql.ResultSet"%>
<%@page import="com.logistics.database.Distributiondatabase"%>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>Orderrank</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<script type="text/javascript" src="scripts/jquery/jquery-1.7.1.js"></script>
	<link href="style/authority/basic_layout.css" rel="stylesheet" type="text/css">
	<link href="style/authority/common_style.css" rel="stylesheet" type="text/css">
	<script type="text/javascript" src="scripts/authority/commonAll.js"></script>
	<script type="text/javascript" src="scripts/fancybox/jquery.fancybox-1.3.4.js"></script>
	<script type="text/javascript" src="scripts/fancybox/jquery.fancybox-1.3.4.pack.js"></script>
	<link rel="stylesheet" type="text/css" href="style/authority/jquery.fancybox-1.3.4.css" media="screen"></link>
	<!--   <script type="text/javascript" src="scripts/artDialog/artDialog.js?skin=default"></script> -->
	<script type="text/javascript" src="scripts/My97DatePicker/WdatePicker.js"></script>
	<script type="text/javascript" src="scripts/Myscripts/alpha_add.js"></script>
  </head>
  
  <body>
  <%
  	String [] ids=new String[5];
  	String[] names=new String[5];
  	String [] sums=new String[5];
  	Map<Integer,Integer> map=new HashMap<Integer,Integer>();
  	Distributiondatabase distributiondatabase=new Distributiondatabase();
  	ResultSet resultSet=distributiondatabase.getOrders();
  	while(resultSet.next())
  	{
  		int id = resultSet.getInt("product_id");
  		int forid = resultSet.getInt("former_order_id");
  		System.out.println("forid:"+forid);
  		String type=resultSet.getString("order_type");
  		if(!type.equals("退货")&&!type.equals("退订")&&forid==0)
  		{
  			if(map.containsKey(id))
  			{
  				int value=(Integer)map.get(id)+1;
  				map.put(id,value);
  			}
  			else
  			{
  				map.put(id,1);
  			}
  		}
  	}
  	for(int i=0;i<5;++i)
  	{
  		ids[i]="";
  		names[i]="";
  		sums[i]="";
  		Iterator iter = map.entrySet().iterator();
  		int max=0;
  		int delete=0;
  		while (iter.hasNext()) {
			Map.Entry entry = (Map.Entry) iter.next();
			int key = (Integer)entry.getKey();
			int val = (Integer)entry.getValue();
			if(val>max)
			{
				delete=key;
				max=val;
				ids[i]=key+"";
				ResultSet tempResultSet=distributiondatabase.productsQuery(key);
				tempResultSet.next();
				names[i]=tempResultSet.getString("product_name");
				sums[i]=val+"";	
			}
		}
		if(delete!=0)
			map.remove(delete);
  	}
   %>
  
   <div id = "add_alpha_id">
  	<div id="container">
  	  <div class = "ui_content">
  	   <div class = "box_border">
  	   <div id = "box_top"><font size=5><lable>最火产品top5</lable></font></div>
  	   </div>
  	   </div>
  	   <div class = "ui_content">
  	    <div class = "box_border">
  	   <table class = "table" width="100%">
  	   	<tr><th><label>名次</label></th><th  align="center"><label>产品id</label></th><th  align="center"><label>产品名</label></th><th  align="center"><label>下单次数</label></th></tr>
  	   	<tr><td><label>1</label></td><td  align="center"><label id="id_id_1"><%=ids[0]%></label></td><td  align="center"><label id="name_id_1"><%=names[0]%></label></td><td  align="center"><label id="sum_id_1"><%=sums[0]%></label></td></tr>
  	   	<tr><td><label>2</label></td><td  align="center"><label id="id_id_2"><%=ids[1]%></label></td><td  align="center"><label id="name_id_2"><%=names[1]%></label></td><td  align="center"><label id="sum_id_2"><%=sums[1]%></label></td></tr>
  	   	<tr><td><label>3</label></td><td  align="center"><label id="id_id_3"><%=ids[2]%></label></td><td  align="center"><label id="name_id_3"><%=names[2]%></label></td><td  align="center"><label id="sum_id_3"><%=sums[2]%></label></td></tr>
  	   	<tr><td><label>4</label></td><td  align="center"><label id="id_id_4"><%=ids[3]%></label></td><td  align="center"><label id="name_id_4"><%=names[3]%></label></td><td  align="center"><label id="sum_id_4"><%=sums[3]%></label></td></tr>
  	   	<tr><td><label>5</label></td><td  align="center"><label id="id_id_5"><%=ids[4]%></label></td><td  align="center"><label id="name_id_5"><%=names[4]%></label></td><td  align="center"><label id="sum_id_5"><%=sums[4]%></label></td></tr>
  	   </table>
  	   </div>
  	   </div>
  	</div>
   </div>
    <script type="text/javascript">
   var eitem = document.getElementById("add_alpha_id");
   window.onload = add_alpha(eitem);
   </script>
  </body>
</html>
